package com.glodon.paas.document.dao.mysql;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.glodon.paas.document.dao.PartDao;
import com.glodon.paas.document.dao.domain.PartEntity;
import com.glodon.paas.document.dao.mapper.PartEntityMapper;

public class PartDaoMysqlImpl implements PartDao {

    @Autowired
    PartEntityMapper partEntityMapper;

    @Override
    public String insert(PartEntity entity) {
        partEntityMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public PartEntity get(String id) {
        return partEntityMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(String id) {
        return partEntityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PartEntity getLatestPartByRevision(String revisionId) {
        return partEntityMapper.getLatestPartByRevision(revisionId);
    }

    @Override
    public void delParts(String revisionId) {
        partEntityMapper.delParts(revisionId);
    }

    @Override
    public List<PartEntity> getPartsByRevision(String revisionId) {
        return partEntityMapper.getPartsByRevision(revisionId);
    }

    @Override
    public int getPartsCountByRevision(String revisionId) {
        Integer rt = partEntityMapper.getPartsCountByRevision(revisionId);
        if (rt != null) {
            return rt.intValue();
        }
        return 0;
    }
}
